<%@page import="org.yate.oa.model.LoginEntity"%>
<%@page import="java.text.SimpleDateFormat, java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set value="${pageContext.request.contextPath}" var="ctx" />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<link href="${ctx}/css/skin.css" rel="stylesheet" type="text/css" />
<link href="${ctx}/css/page.css" rel="stylesheet" type="text/css" />
<link href="${ctx}/css/jquery-ui.css" rel="stylesheet" type="text/css" />
<style type="text/css">
table {
	table-layout: fixed;
}

#staffs td {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
</style>
<script type="text/javascript" src="${ctx}/js/jquery.js"></script>
<script type="text/javascript" src="${ctx}/js/backOffice.js"></script>
<script type="text/javascript" src="${ctx}/js/jquery.myPagination.js"></script>
<script type="text/javascript" src="${ctx}/js/jquery-ui.min.js"></script>
<script type="text/javascript">
	var currPage = 1;
	var obj = {
		on : true,
		type : 'all',
		branch : '',
		searchVal : '',
		searchVal2 : '',
		pageSize : 10
	};
	$(document)
			.ready(
					function() {
						for ( var i = 1; i <= 12; i++) {
							$("#selMonth").append(
									"<option value='"+i+"'>" + i + "</option>");
						}
						$("#selMonth").val((new Date().getMonth()));
						$("#selMonth").change(function() {
							page(1);
						});
						$("#searchVal1,#searchVal2").datepicker({
							changeMonth : true,
							changeYear : true,
							dateFormat : 'yy-mm-dd',
							maxDate : new Date()
						});
						page(1);
						$
								.ajax({
									type : 'post',
									dataType : 'json',
									url : '${ctx}/performance/post',
									data : {
										type : 'branch'
									},
									success : function(data) {
										if (data.status == 200) {
											var str = '';
											data = data.data;
											str += '<option selected="selected" value="">请选择</option>';
											for ( var i = 0; i < data.length; i++) {
												str += '<option value="'+data[i].id+'">'
														+ data[i].orgName
														+ '</option>';
											}
											$('#branch').html(str);
										}
									}
								});

						$("#selPageSize")
								.html(
										"<option value='10'>10</option><option value='30'>30</option><option value='50'>50</option><option value='100'>100</option><option value='200'>200</option>");
						$("#selPageSize").change(function() {
							changePageSize();
						});
					});
	function changePageSize() {
		obj.pageSize = $("#selPageSize").val();
		page(0);
	}
	function page(pageIndex) {
		currPage = pageIndex;
		var sm = $("#selMonth").val();
		if (parseInt(sm) < 10) {
			sm = "0" + sm;
		}
		obj.date = new Date().getFullYear() + "" + sm;
		$("#demo1").myPagination({
			currPage : pageIndex,
			ajax : {
				on : true,
				dataType : 'json',
				url : '${ctx}/performance/post',
				callback : 'showData',
				param : obj
			}
		});
	}

	function changeStatus(op, pid) {
		var obj = {};
		obj.type = "changestatus";
		if (op == "1") {
			//HR审核通过
			obj.status = "hrcompleted";
		} else if (op == "2") {
			//HR审核不通过
			obj.status = "completed";
		}
		obj.pid = pid;
		$.ajax({
			type : 'post',
			dataType : 'json',
			data : obj,
			url : '${ctx}/performance/post',
			success : function(data) {
				if (data.code == 200) {
					$.msgbox.show({
						message : "操作成功",
						icon : 'ok',
						beforeHide : function() {
							page(currPage);
							//location.reload();
						}
					});
				} else {
					$.msgbox.show({
						message : data.msg,
						icon : 'no',
						beforeHide : function() {
							//location.reload();
							page(currPage);
						}
					});
				}
			}
		});
	}

	function showData(data) {
		var rows = data.data.rows;
		var c0 = 0, c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0, c6 = 0, c7 = 0;
		var tmpTotalScore = 0;
		var tmpStatus;
		var str = '';
		for ( var i = 0; i < rows.length; i++) {
			if (rows[i].status == 'zlcompleted') {
				tmpStatus = "待审核";
			} else if (rows[i].status == 'hrcompleted') {
				tmpStatus = "已审核";
			} else {
				tmpStatus = "处理中";
			}
			if (rows[i].status == "zlcompleted"
					|| rows[i].status == "hrcompleted") {
				c0++;
				tmpTotalScore = parseFloat(rows[i].totalScore);
				if (tmpTotalScore == 0) {
					c1++;
				} else if (tmpTotalScore < 80) {
					c2++;
				} else if (tmpTotalScore >= 80 && tmpTotalScore < 90) {
					c3++;
				} else if (tmpTotalScore >= 90 && tmpTotalScore <= 95) {
					c4++;
				} else if (tmpTotalScore > 95 && tmpTotalScore <= 100) {
					c5++;
				} else if (tmpTotalScore > 100 && tmpTotalScore <= 105) {
					c6++;
				} else if (tmpTotalScore > 105) {
					c7++;
				}
			}
			str += '<tr>';
			str += '<td height="30" class="left_txt2" align="middle">'
					+ ((currPage - 1) * 10 + (i + 1)) + '</td>';
			str += '<td height="30" class="left_txt2" align="middle">'
					+ rows[i].partName + '</td>';
			str += '<td height="30" class="left_txt2" align="middle">'
					+ rows[i].creater.trueName + '</td>';
			str += '<td height="30" class="left_txt2" align="middle">'
					+ rows[i].targetUser.trueName + '</td>';
			str += '<td height="30" class="left_txt2" align="middle">'
					+ tmpStatus + '</td>';
			str += '<td height="30" class="left_txt2" align="middle">'
					+ new Date(rows[i].beginPeriod).toLocaleDateString() + '至'
					+ new Date(rows[i].endPeriod).toLocaleDateString()
					+ '</td>';
			str += '<td height="30" class="left_txt2" align="middle">'
					+ new Date(rows[i].creationDate).toLocaleString() + '</td>';
			str += '<td height="30" class="left_txt2" align="middle">'
					+ rows[i].totalScore + '</td>';
			str += '<td height="30" class="left_txt2" align="middle"><a target="_blank" href="${ctx}/jsp/dataMgt/performanceShow.jsp?pid='
					+ rows[i].id + '">查看</a>';
			if (rows[i].status == 'zlcompleted') {
				str += '&nbsp;&nbsp;<a href="javascript:void(0);" onclick="changeStatus(1,'
						+ rows[i].id
						+ ')">通过</a>&nbsp;&nbsp;<a href="javascript:void(0);" onclick="changeStatus(2,'
						+ rows[i].id + ')">不通过</a></td>';
			} else {
				str += '</td>';
			}
			str += '</tr>';
		}
		str += '<tr><td colspan="9" height="30" class="left_txt2">'
				+ ($("#branch").find("option:selected").text() == "请选择" ? ""
						: ("部门：" + $("#branch").find("option:selected").text() + "，"))
				+ '&nbsp;&nbsp;&nbsp;有效总数：' + c0 + '，&nbsp;&nbsp;&nbsp;80分以下：'
				+ c2 + '个，&nbsp;&nbsp;&nbsp;80以上-90分：' + c3
				+ '个，&nbsp;&nbsp;&nbsp;90以上-95分：' + c4
				+ '个，&nbsp;&nbsp;&nbsp;95以上-100分：' + c5
				+ '个，&nbsp;&nbsp;&nbsp;100以上-105分：' + c6
				+ '个，&nbsp;&nbsp;&nbsp;105分以上：' + c7 + '个</td></tr>';
		if (c0 > 0 && $("#branch").find("option:selected").text() != "请选择") {
			str += '<tr><td colspan="9" height="30" class="left_txt2">强制比例分布：&nbsp;&nbsp;&nbsp;'
					+ '1.2='
					+ (parseFloat(c7 / c0) * 100).toFixed(2)
					+ '%&nbsp;&nbsp;&nbsp;'
					+ '1.1='
					+ (parseFloat(c6 / c0) * 100).toFixed(2)
					+ '%&nbsp;&nbsp;&nbsp;'
					+ '1.0='
					+ (parseFloat(c5 / c0) * 100).toFixed(2)
					+ '%&nbsp;&nbsp;&nbsp;'
					+ '0.8='
					+ (parseFloat(c4 / c0) * 100).toFixed(2)
					+ '%&nbsp;&nbsp;&nbsp;'
					+ '0.5='
					+ (parseFloat(c3 / c0) * 100).toFixed(2)
					+ '%&nbsp;&nbsp;&nbsp;'
					+ '0='
					+ (parseFloat(c2 / c0) * 100).toFixed(2)
					+ '%'
					+ '</td></tr>';
		}
		$('#staffs').html('').html(str);
	}
	function exportExcel() {
		var branch = $('#branch').select().val();
		var sm = $("#selMonth").val();
		if (parseInt(sm) < 10) {
			sm = "0" + sm;
		}
		sm = new Date().getFullYear() + "" + sm;
		$("#ifmExcel").attr(
				"src",
				"${ctx}/performance/post?type=excel&date=" + sm + "&branch="
						+ branch);
	}

	function approval(op) {
		if ($("#branch").find("option:selected").text() == "请选择") {
			$.msgbox.show({
				message : '请按部门进行批量审核',
				icon : 'no',
				beforeHide : function() {
					$("#queryDiv").show();
				}
			});
			return;
		}
		$("input[name='btnApproval']").hide();
		$("#imgWait").show();
		var obj = {};
		var branch = $('#branch').select().val();
		var sm = $("#selMonth").val();
		if (parseInt(sm) < 10) {
			sm = "0" + sm;
		}
		sm = new Date().getFullYear() + "" + sm;
		obj.type = "approval";
		obj.branch = branch;
		obj.op = op;
		obj.date = sm;

		$.ajax({
			type : 'post',
			dataType : 'json',
			data : obj,
			url : '${ctx}/performance/post',
			success : function(data) {
				if (data.status == 200) {
					$.msgbox.show({
						message : "操作成功",
						icon : 'ok',
						beforeHide : function() {
							page(currPage);
							//location.reload();
						}
					});
				} else {
					$.msgbox.show({
						message : data.msg,
						icon : 'no',
						beforeHide : function() {
							//location.reload();
							page(currPage);
						}
					});
				}
			}
		});
		$("#imgWait").hide();
		$("input[name='btnApproval']").show();
	}

	function search() {
		var branch = $('#branch').select().val();
		obj.branch = branch;
		page(1);
	}
</script>
</head>
<body style="font-size: 62.5%;">
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td width="17" height="29" valign="top"
				background="${ctx}/images/mail_leftbg.gif"><img
				src="${ctx}/images/left-top-right.gif" width="17" height="29" /></td>
			<td width="" height="29" valign="top"
				background="${ctx}/images/content-bg.gif"><table width="100%"
					height="31" border="0" cellpadding="0" cellspacing="0"
					class="left_topbg" id="table2">
					<tr>
						<td height="31"><div class="titlebt">绩效数据</div></td>
					</tr>
				</table></td>
			<td width="16" valign="top"
				background="${ctx}/images/mail_rightbg.gif"><img
				src="${ctx}/images/nav-right-bg.gif" width="16" height="29" /></td>
		</tr>
		<tr>
			<td height="71" valign="middle"
				background="${ctx}/images/mail_leftbg.gif">&nbsp;</td>
			<td valign="top" bgcolor="#F7F8F9"><table width="100%"
					height="138" border="0" cellpadding="0" cellspacing="0">
					<tr>
						<td height="13" valign="top">&nbsp;</td>
					</tr>
					<tr>
						<td valign="top"><table width="98%" border="0" align="center"
								cellpadding="0" cellspacing="0">
								<tr>
									<td class="left_txt">当前位置：绩效数据</td>
								</tr>
								<tr>
									<td height="20"><table width="100%" height="1" border="0"
											cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
											<tr>
												<td></td>
											</tr>
										</table></td>
								</tr>
								<tr>
									<td>
										<button onclick="exportExcel()">导出到Excel</button> <input
										type="button" name="btnApproval" onclick="approval('1')"
										value="通过" /> <input type="button" name="btnApproval"
										onclick="approval('2')" value="不通过" /> 每页显示：<select
										id='selPageSize'></select>条 <img src="${ctx }/images/wait.gif"
										id="imgWait" style="display: none;" />
									</td>
								</tr>
								<tr>
									<td><table width="100%" height="31" border="0"
											cellpadding="0" cellspacing="0" class="nowtable">
											<tr>
												<td class="left_bt2">&nbsp;&nbsp;&nbsp;&nbsp;绩效数据</td>
												<td width="5%" align="right"><img
													onclick="if($('#queryDiv').is(':visible')){$('#queryDiv').hide()}else{$('#queryDiv').show()}"
													src="${ctx }/images/query.png" style="cursor: pointer;"></img>&nbsp;</td>
											</tr>
										</table></td>
								</tr>
								<tr>
									<td width="100%" valign="top"
										style="min-height: 350px; height: 350px;">
										<table class="tblExcel" cellpadding="0" cellspacing="0">
											<thead>
												<tr>
													<td height="30" width="4%" class="left_txt2" align="center">序号</td>
													<td height="30" width="20%" class="left_txt2"
														align="center">名称</td>
													<td height="30" width="5%" class="left_txt2" align="center">考核者</td>
													<td height="30" width="5%" class="left_txt2" align="center">被考核者</td>
													<td height="30" width="5%" class="left_txt2" align="center">状态</td>
													<td height="30" width="20%" class="left_txt2"
														align="center">考核周期</td>
													<td height="30" width="20%" class="left_txt2"
														align="center">创建时间</td>
													<!-- <td height="30" width="8%" class="left_txt2" align="center">状态</td> -->
													<td height="30" width="8%" class="left_txt2" align="center">主管打分</td>
													<td height="30" width="12%" class="left_txt2"
														align="center">操作</td>
												</tr>
											</thead>
											<tbody id="staffs"></tbody>
										</table>
										<div id="demo1"></div>
									</td>
								</tr>
							</table></td>
					</tr>
				</table></td>
			<td background="${ctx}/images/mail_rightbg.gif">&nbsp;</td>
		</tr>
		<tr>
			<td valign="middle" background="${ctx}/images/mail_leftbg.gif"><img
				src="${ctx}/images/buttom_left2.gif" width="17" height="17" /></td>
			<td height="17" valign="top"
				background="${ctx}/images/buttom_bgs.gif"><img
				src="${ctx}/images/buttom_bgs.gif" width="17" height="17" /></td>
			<td background="${ctx}/images/mail_rightbg.gif"><img
				src="${ctx}/images/buttom_right2.gif" width="16" height="17" /></td>
		</tr>
	</table>
	<div id="queryDiv"
		style="background-color: #E1E5EE; width: 293px; height: 135px; position: absolute; top: 141px; right: 27px; display: none;">
		<form>
			<table cellpadding="0" cellspacing="0" style="font-size: 13px;">
				<tr>
					<td height="35" align="right"><label>部门：</label></td>
					<td><select id="branch">
							<option selected="selected" value="">请选择</option>
					</select></td>
				</tr>
				<tr>
					<td height="35" align="right"><label>月份：</label></td>
					<td><select id="selMonth">
					</select></td>
				</tr>
				<tr>
					<td valign="top" align="center" colspan="2" height="35"><input
						type="button" value="确定" onclick="search()" /> <input
						type="reset" value="重置" /></td>
				</tr>
			</table>
		</form>
	</div>
	<iframe id="ifmExcel" style="width: 0px; height: 0px;"></iframe>
</body>
</html>